﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace DatabaseSetup
{
    class Program
    {
        static void Main(string[] args)
        {
            // display initial message
            Console.WriteLine("Setup Database...");

            // retrieve the user data application directory
            var dataAppPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            // get the path to the PatternManagementExtension directory
            var directoryPath = Path.Combine(dataAppPath, "PatternManagementExtension");

            // clean up the PatternManagementExtension directory
            if (Directory.Exists(directoryPath))
            {
                Directory.Delete(directoryPath, true);
            }

            // re-create the PatternManagementExtension directory
            Directory.CreateDirectory(directoryPath);

            // copy necessary files to the directory
            var execDirectoryPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var dbFilesDirectoryPath = Path.Combine(execDirectoryPath, "DBFiles");
            var dbFilesDirectory = new DirectoryInfo(dbFilesDirectoryPath);
            foreach (var file in dbFilesDirectory.GetFiles())
            {
                var destinationFilePath = Path.Combine(directoryPath, file.Name);
                File.Copy(file.FullName, destinationFilePath, true);
            }
            foreach (var folder in dbFilesDirectory.GetDirectories())
            {
                var destinationFolderPath = Path.Combine(directoryPath, folder.Name);
                Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(folder.FullName, destinationFolderPath);
            }

            // display ending message
            Console.WriteLine("Setup completed");
        }
    }
}
